<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="a002.css" rel="stylesheet" type="text/css" title="a002_css"/>
        <script>
            var msgStr_loginHint = "請輸入帳號及碼密碼";
            var msgStr_loginSucc = "登入成功";
            var msgStr_loginFail = "登入失敗，請再試一次";
        </script>
        <script>
            var xmlhttp;
            function srvr_rslt_chk() {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                    try {
                        var rslt = JSON.parse(xmlhttp.responseText);
                        if (rslt.login_success) {
                            login_msg.innerHTML = msgStr_loginSucc;
                            //
                            setTimeout(function() {
//                                login_form.action = "a001.html";
                                login_form.action = "a001f";
                                login_form.submit();
                                //
                                login_form.usr_id.disabled = false;
                                login_form.usr_pwd.disabled = false;
                                //
                            }, 500);
                        } else {
                            login_msg.innerHTML = msgStr_loginFail;
                            login_form.usr_id.disabled = false;
                            login_form.usr_pwd.disabled = false;
                            login_form.usr_pwd.value = "";

                        }
                    } catch (err) {
                        login_form.usr_id.disabled = false;
                        login_form.usr_pwd.disabled = false;
                        login_form.usr_pwd.value = "";
                    }
                }

            }
            function my_submit() {
                if (!xmlhttp) {
                    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                        xmlhttp = new XMLHttpRequest();
                    } else {// code for IE6, IE5
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                xmlhttp.onreadystatechange = srvr_rslt_chk;
                xmlhttp.open("POST", "/W001/d001/a001_auth", true);
                xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlhttp.send("usr_id=" + login_form.usr_id.value + "&usr_pwd=" + login_form.usr_pwd.value);
                //
                login_form.usr_id.disabled = true;
                login_form.usr_pwd.disabled = true;
            }
            function input_keypress_trigger() {
                if (!usr_id.onkeyup) {
                    usr_id.onkeyup = function(e) {
                        if (e.keyCode === 13) {
                            my_submit();
                        }
                    };
                }
                if (!usr_pwd.onkeyup) {
                    usr_pwd.onkeyup = function(e) {
                        if (e.keyCode === 13) {
                            my_submit();
                        }
                    };
                }
            }
        </script>
    </head>

    <!--<div id="dragon_bg"></div>-->
    <img id="dragon_bg" src="images/dragon.png" alt="dragon02.png"/>
    <div class="login_box">
        <div class="title">Title(中文)</div>
        <form id="login_form" name="login_form">
            <div class="login_row">
                <span class="login_lbl" >使用者名稱:</span>
                <input type="text" id="usr_id" class="login_fld" onkeypress="javascript:input_keypress_trigger()"/>
            </div>
            <div class="login_row">
                <span class="login_lbl">使用者密碼:</span>
                <input type="password" id="usr_pwd" class="login_fld" onkeypress="javascript:input_keypress_trigger()"/>
            </div>
            <div class="login_btns">
                <input type="button" value="確認" class="login_btn" onclick="javascript:my_submit()" />
                <input type="reset" value="取消" class="login_btn"/>
            </div>
        </form>
        <div id="login_msg">請輸入帳號及密碼</div>
    </div>

</html>
